﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.DrugTrade.BLLFactory;
using System.Collections.Generic;
using HZ.DrugTrade.IBLL;

namespace HZ.DrugTrade.Web.CommonPage
{
    public partial class CompanyInfo : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            this.Header.Title = "企业信息查看";

            //绑定企业基本信息
            if (!IsPostBack)
            {
                //string companyId = Request.QueryString["companyId"];
                //IBLL_Company companyCtrl = Factory.BLL_Company();
                //HZ.DrugTrade.Model.CompanyInfo cominfo = companyCtrl.GetCompanyInfoByID(companyId);
                string comPS_Id = Request.QueryString["companyId"].ToString();
                this.lblSort.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyType(comPS_Id);
                HZ.DrugTrade.Model.CompanyInfo com = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyInfoByID(comPS_Id);
                if (com != null)
                {
                    this.lblAddress.Text = com.Address;//联系地址
                    this.lbladulterant.Text = com.Adulterant;//两年内有无假药记录
                    this.lblAuthor.Text = com.Author;//被授权人
                    this.lblAuthorCell.Text = com.AuthorCell;//被授权人手机
                    this.lblCellPhone.Text = com.CellNo;//联系人手机
                    this.lblComCode.Text = com.Comcode;//企业代码证号
                    this.lblComEndTime.Text = Constants.ReturnTime(com.ComEndtime);//企业代码证有效期
                    this.lblComFax.Text = com.Fax;//企业传真
                    this.lblComName.Text = com.CompanyName;//企业名称
                    this.lblComTel.Text = com.TelNo;//企业联系电话
                    this.lbldevious.Text = com.Devious;//是否有不正当行为
                    this.lblEmail.Text = com.Email;//电子信箱
                    this.lblPermission.Text = com.Permission;//营业执照号
                    if (com.Permissionloogtime != 1)
                    {
                        this.lblPermissionDate.Text = Constants.ReturnTime(com.PermissionDate);//营业执照期限
                    }
                    else
                    {
                        this.lblPermissionDate.Text = "长期";
                    }
                    this.lblPermissionCheckDate.Text = Constants.ReturnTime(com.PermissionCheckDate);//营业执照年检日期
                    this.lblPermitLicence.Text = com.BusinessCertificate;//生产或经营许可证号
                    if (com.Businessloogtime != 1)
                    {
                        this.lblPermitLicenceEndTime.Text = Constants.ReturnTime(com.BusinessCertificateDate);//许可证有效期
                    }
                    else
                    {
                        this.lblPermitLicenceEndTime.Text = "长期";//许可证有效期
                    }

                    this.lblPermitLicenceRange.Text = com.BusinessRange;//经营范围
                    this.lblPostCode.Text = com.PostCode;//邮政编码
                    this.lblRegisterAddress.Text = com.RegistAddress;//企业注册地址
                    this.lblRegisterFund.Text = com.RegisterFund.ToString();//企业注册资金
                    this.lblStoreHouseAddress.Text = com.StoreHouseAddress;//仓库地址
                    this.lblLawerPerson.Text = com.LayMan;//法人
                    this.lblInstruments.Text = com.Instruments;//医疗器械许可证号
                    this.lblContactPerson.Text = com.ContactPerson;//企业联系人
                    this.lblRemarks.Text = com.Remarks;//备注
                    this.lblUserCode.Text = comPS_Id;//企业用户编号

                    IBLL_User iu = Factory.BLL_User();
                    int TotalCount = 0;
                    IList<HZ.DrugTrade.Model.View.OrgUsers> listUser = iu.GetOrgUsersByWhere(new Model.Query.OrgUsers() { RoleID = "02", OrgID = comPS_Id, SortFields = " LastLoginTime DESC" }, 1, 0, out TotalCount);
                    //置空用户IDs字符串
                    if (listUser.Count > 0)
                    {
                        HZ.DrugTrade.Model.View.OrgUsers user = listUser[0];
                        lblLastlogin.Text = user.LastLoginTime.HasValue ? user.LastLoginTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "<font color=red>从未登录过</font>";
                    }
                    else
                    {
                        lblLastlogin.Text = "<font color=red>从未登录过</font>";
                    }

                }
                else
                {
                    PageError("企业不存在！", "");
                }
            }
        }
    }
}
